/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
export var searchInsert = function (nums, target) {
  let left = 0
  let right = nums.length - 1
  while (left <= right) {
    const current = (right + left) >> 1
    if (nums[current] === target) {
      return current
    }
    if (nums[current] > target) {
      right = current - 1
    } else {
      left = current + 1
    }
  }
  return left
}
